const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const user = require('../../services/user.js');

//获取应用实例
const app = getApp()
Page({
  data: {
    newGoods: [],
    hotGoods: [],
    topics: [],
    brands: [],
    floorGoods: [],
    banner: [],
    channel: []
  },
  onShareAppMessage: function () {
    return {
      title: 'NideShop',
      desc: '枝枝数商城',
      path: '/pages/index/index'
    }
  },

  getIndexData: function () {
    let that = this;
           that.setData({
             banner: [
               {image_url: '/static/images/banner01.jpg', link: '/pages/newGoods/newGoods?title=ss' }, 
               {image_url: '/static/images/banner02.jpg', link: '/pages/hotGoods/hotGoods'}, 
               {image_url: '/static/images/banner03.jpg', link: '/pages/ucenter/address/address'}],
             channel:[
               { icon_url:'/static/images/home.png',name:'居家'},
               { icon_url: '/static/images/kitchen.png', name: '餐厨'},
               { icon_url: '/static/images/parts.png', name: '配件' },
               { icon_url: '/static/images/clothing.png', name: '服装' },
               { icon_url: '/static/images/menu.png', name: '更多' }
             ],
 
 
        });
    util.request(api.getLabelGoods).then(function (res) {
      console.log(res);
            that.setData({
        newGoods: res.tjzq,
        hotGoods: res.rqrm,
        topics:res.qxsj,
        brand:res.zgtj
      })


    })
   
  },
  onLoad: function (options) {
    this.getIndexData();
  },
  onReady: function () {
    // 页面渲染完成
    
  },
  onShow: function () {
    let that=this;
    // 页面显示
    let likeGoods=setInterval(function(){
      if(util.session == undefined){

      }else{
        util.request(api.guessYouLike, { openId: util.session }, 'GET').then(res => {
          that.setData({
            floorGoods: [{
              name: '猜你喜欢', goodsList: res
            }]
          })
          clearInterval(likeGoods);
        })
      }
    },1000)
    
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
})
